//
//  CellModelFrame.m
//  Edu_iOS2018
//
//  Created by apple on 2018/1/12.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#define IconOfImageWidth 108    //头像宽高
#define PaddingOfView    45

#import "CellModelFrame.h"
#import "ContactDateHelper.h"

@implementation CellModelFrame

-(void)setContentOfCellWith:(CellModel *)model andLastModel:(CellModel *)lastModel{
    _cellModel = model;
    
    //设置时间位置
    _timeF = CGRectMake(0, 0, kScreenWidth,12);
    
    //设置头像
    if ([self.cellModel.type isEqualToString:@"they"]) {
        _headImageViewF = CGRectMake(kProportion_Width(45), 1 + CGRectGetMaxY(self.timeF), kProportion_Width(IconOfImageWidth), kProportion_Height(IconOfImageWidth));
    }else{
        _headImageViewF = CGRectMake(kScreenWidth-kProportion_Width(IconOfImageWidth)-kProportion_Width(30), 1 + CGRectGetMaxY(self.timeF), kProportion_Width(IconOfImageWidth), kProportion_Height(IconOfImageWidth));
    }
    //设置正文
    CGRect textRect = [self.cellModel.content boundingRectWithSize:CGSizeMake(kProportion_Width(650), MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.f]} context:nil];
    if ([self.cellModel.type isEqualToString:@"they"]) {
        textRect.origin.x = CGRectGetMaxX(self.headImageViewF)+kProportion_Width(30);
        textRect.origin.y = CGRectGetMaxY(self.timeF);
    }else{
        textRect.origin.x = kScreenWidth-kProportion_Width(45)-kProportion_Width(IconOfImageWidth)-textRect.size.width-35;
        textRect.origin.y = CGRectGetMaxY(self.timeF);
    }
    _textF = CGRectMake(textRect.origin.x, textRect.origin.y + 2, textRect.size.width+30, textRect.size.height+12);
    
    //得到行高
    _cellHight=MAX(CGRectGetMaxY(self.headImageViewF), CGRectGetMaxY(self.textF)) + 15;
}

-(void)setCellModel:(CellModel *)cellModel{
    _cellModel=cellModel;

    //设置时间位置
    _timeF = CGRectMake(0, 0, kScreenWidth,12);
    
    //设置头像
    if ([self.cellModel.type isEqualToString:@"they"]) {
        _headImageViewF = CGRectMake(kProportion_Width(45), 1 + CGRectGetMaxY(self.timeF), kProportion_Width(IconOfImageWidth), kProportion_Height(IconOfImageWidth));
    }else{
        _headImageViewF = CGRectMake(kScreenWidth-kProportion_Width(IconOfImageWidth)-kProportion_Width(30), 1 + CGRectGetMaxY(self.timeF), kProportion_Width(IconOfImageWidth), kProportion_Height(IconOfImageWidth));
    }
    //设置正文
    CGRect textRect = [self.cellModel.content boundingRectWithSize:CGSizeMake(kProportion_Width(650), MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.f]} context:nil];
    if ([self.cellModel.type isEqualToString:@"they"]) {
        textRect.origin.x = CGRectGetMaxX(self.headImageViewF)+kProportion_Width(30);
        textRect.origin.y = CGRectGetMaxY(self.timeF);
    }else{
        textRect.origin.x = kScreenWidth-kProportion_Width(45)-kProportion_Width(IconOfImageWidth)-textRect.size.width-35;
        textRect.origin.y = CGRectGetMaxY(self.timeF);
    }
    _textF = CGRectMake(textRect.origin.x, textRect.origin.y + 2, textRect.size.width+30, textRect.size.height+12);
    
    //得到行高
    _cellHight=MAX(CGRectGetMaxY(self.headImageViewF), CGRectGetMaxY(self.textF)) + 15;
    
}

@end
